package LeetCode1;

import java.util.LinkedList;
import java.util.Queue;

//对程二叉树层序遍历
public class Num101NonRecursion {
    public boolean isSymmetric(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root.left);
        queue.offer(root.right);
        while (!queue.isEmpty()) {
            TreeNode p = queue.poll();
            TreeNode q = queue.poll();
            if (p == null && q == null) {
                //节点为空，进入下一次循环
                continue;
            }
            if (p == null || q == null) {
                return false;
            }
            if (p.val != q.val) {
                return false;
            }
            //此时表示值相等，录入两组对比子节点
            queue.offer(p.left);
            queue.offer(q.right);
            queue.offer(p.right);
            queue.offer(q.left);
        }
        //符合条件后
        return true;
    }
}
